package com.ymx.darling.type;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.Year;

public class YearHandler implements TypeHandler<Year> {
    @Override
    public Year getResult(ResultSet resultSet, int columIndex) throws SQLException {
        int year = resultSet.getInt(columIndex);
        return year == 0 ? null : Year.of(year);
    }

    @Override
    public void setParameter(PreparedStatement statement, Year value, int index) throws SQLException {
        statement.setInt(index, value.getValue());
    }
}
